/**
 * Created by Feng on 2016/3/25.
 */
import {provide, Directive, forwardRef, Input} from '@angular/core';
import {Control, NG_VALIDATORS, Validator} from '@angular/common';
/* beautify ignore:end */



@Directive({
    selector: '[min-size]',
    providers: [provide(NG_VALIDATORS, {useExisting: MinSizeValidator, multi: true})]
})

export class MinSizeValidator implements Validator {
    @Input('min-size') size: string;
    validate(c: Control): {[key: string]: any} {
        let value = c.value;
        if(value == null )
            return null;
        if(value.replace(/[^\x00-\xff]/g, "**").length >= parseInt(this.size)){
            return null;
        } 
        return {"minSize":true};
    }
}